package no1177;

import java.util.*;

public class No1177 {
    public static void main(String[] args) {
        String s = "abcda";
        int[][] queries = {{3,3,0},{1,2,0},{0,3,1},{0,3,2},{0,4,1}};
        List<Boolean> booleans = new No1177().canMakePaliQueries(s, queries);
        System.out.println(booleans.toString());
    }

    public List<Boolean> canMakePaliQueries(String s, int[][] queries) {
        ArrayList<Boolean> list = new ArrayList<>();
        for (int i = 0; i < queries.length; i++) {
            String substring = s.substring(queries[i][0], queries[i][1]+1);
            HashMap<Character, Integer> map = new HashMap<>();
            for (int j = 0; j < substring.length(); j++) {
                char c = substring.charAt(j);
                if(map.containsKey(c)) {
                    map.put(c,map.get(c)+1);
                } else {
                    map.put(c,1);
                }
            }

            Integer[] values = map.values().toArray(new Integer[0]);
            int count = 0;
            for (Integer value : values) {
                if (value % 2 == 1) {
                    count++;
                }
            }

            if(((count / 2) + (count % 2))<= ((substring.length() % 2) + queries[i][2])){
                list.add(true);
            } else  {
                list.add(false);
            }
        }
        return list;
    }
}
